// ref: https://umijs.org/config/
import { primaryColor } from '../src/defaultSettings';

export default {
  plugins: [
    [
      'umi-plugin-react',
      {
        antd: true,
        dva: {
          hmr: true,
        },
        targets: {
          ie: 11,
        },
        locale: {
          enable: true, // default false
          default: 'zh-CN', // default zh-CN
          baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
        },
        dynamicImport: {
          loadingComponent: './components/PageLoading/index',
        },
      },
    ],
    [
      'umi-plugin-pro-block',
      {
        moveMock: false,
        moveService: false,
        modifyRequest: true,
        autoAddMenu: true,
      },
    ],
  ],
  targets: {
    ie: 11,
  },

  /**
   * 路由相关配置
   */
  routes: [
    {
      path: '/user',
      component: '../layouts/UserLayout',
      routes: [
        { path: '/user', redirect: '/user/login' },
        { path: '/user/login', component: './User/Login' },
        { path: '/user/register', component: './User/Register' },
        { path: '/user/register-result', component: './User/RegisterResult' },
      ],
    },
    {
      path: '/preview/competition/:id',
      component: './Preview/competition/$id/index.js',
      routes: [
        {
          path: '/preview/competition/:id/',
          redirect: '/preview/competition/:id/publicity',
        },
        {
          path: '/preview/competition/:id/publicity',
          component: './Preview/competition/$id/publicity.js'
        },
        {
          path: '/preview/competition/:id/enroll',
          component: './Preview/competition/$id/enroll.js'
        },
        {
          path: '/preview/competition/:id/competition',
          component: './Preview/competition/$id/competition.js'
        },
        {
          path: '/preview/competition/:id/paper',
          component: './Preview/competition/$id/paper.js'
        },
        {
          path: '/preview/competition/:id/grade',
          component: './Preview/competition/$id/grade.js',
          authority: ['teacher'],
        },
        {
          path: '/preview/competition/:id/charts',
          component: './Preview/competition/$id/charts.js',
        },
        {
          path: '/preview/competition/:id/result',
          component: './Preview/competition/$id/result.js',
        },
      ]
    },
    {
      path: '/setting/',
      component: '../layouts/CompetitionLayout',
      routes: [
        {
          path: '/setting',
          redirect: '/setting/index',
        },
        {
          path: '/setting/index',
          name: 'setting',
          routes: [
            {
              path: '/setting/index/',
              redirect: '/setting/index/messagesetting'
            },
            {
              path: '/setting/index/messagesetting',
              name: 'messageSetting',
              component: './Setting/MessageSetting/index',
            },
            {
              path: '/setting/index/imagesetting',
              name: 'imageSetting',
              component: './Setting/ImageSetting/index',
            },
            {
              path: '/setting/index/enteredsetting',
              name: 'enteredSetting',
              component: './Setting/EnteredSetting/index',
            },
          ]
        },
        {
          path: '/setting/paper',
          name: 'paper',
          //component: './Paper/index',
          routes: [
            {
              path: '/setting/paper',
              redirect: '/setting/paper/papercreate'
            },
            {
              path: '/setting/paper/papercreate',
              name: 'paperCreate',
              component: './Paper/PaperCreate/index',
              routes: [
                {
                  path: '/setting/paper/papercreate',
                  redirect: '/setting/paper/papercreate/simpleselection',
                },
                {
                  path: '/setting/paper/papercreate/simpleselection',
                  component: './Paper/PaperCreate/SimpleSelection/index',
                },
              ]
            },
          ]
        },
        {
          path: '/setting/grade',
          name: 'grade',
          routes: [
            {
              path: '/setting/grade',
              redirect: '/setting/grade/gradeSetting'
            },
            {
              path: '/setting/grade/gradeSetting',
              name: 'gradeSetting',
              component: './Setting/GradeSetting/index',
            },
          ]
        },
      ]
    },
    {
      path: '/',
      component: '../layouts/BasicLayout',
      authority: ['admin', 'user', 'teacher'],
      routes: [
        { path: '/', redirect: '/welcome' },
        // dashboard
        {
          path: '/welcome',
          name: 'welcome',
          icon: 'smile',
          component: './Welcome',
        },

        {
          path: '/competition',
          name: 'competition',
          icon: 'solution',
          routes: [
            {
              name: 'manage',
              path: '/competition/manage',
              component: './Competition/Manage/index',
              authority: ['admin'],
            },
            {
              name: 'competitionList',
              path: '/competition/list',
              component: './Competition/List/index',
              authority: ['user'],
            },
            {
              name: 'enrollList',
              path: '/competition/enrollList',
              component: './Competition/EnrollList/index.js',
              authority: ['user'],
            },
            {
              name: 'review',
              path: '/competition/review',
              component: './Competition/Review/index.js',
              authority: ['teacher'],
            },
          ]
        },
        // {
        //   path: '/question',
        //   name: 'question',
        //   icon: 'question',
        //   authority: ['admin'],
        //   routes: [
        //     {
        //       name: 'bank',
        //       path: '/question/bank',
        //       component: './Question/Bank/index',
        //     },

        //   ]
        // },
        {
          path: '/account',
          name: 'account',
          icon: 'user',
          Routes: ['src/pages/Authorized'],
          authority: ['admin', 'user', 'teacher'],
          routes: [
            {
              name: 'center',
              path: '/account/center',
              component: './Account/Center/index',
            },
            {
              path: '/account/settings',
              name: 'settings',
              component: './Account/Settings/Info',
              routes: [
                {
                  path: '/account/settings',
                  redirect: '/account/settings/base',
                },
                {
                  path: '/account/settings/base',
                  component: './Account/Settings/BaseView',
                },
                {
                  path: '/account/settings/security',
                  component: './Account/Settings/SecurityView',
                },
                {
                  path: '/account/settings/binding',
                  component: './Account/Settings/BindingView',
                },
                {
                  path: '/account/settings/notification',
                  component: './Account/Settings/NotificationView',
                },
              ],
            },
            {
              name: 'userManage',
              path: '/account/userManage',
              component: './Account/userManage/index',
              authority: ['admin'],
            },
          ]
        },

      ],
    },
    {
      path: '/exception',
      routes: [
        // exception
        {
          path: '/exception/403',
          component: './403',
        },
        {
          path: '/exception/404',
          component: './404',
        },
        {
          path: '/exception/500',
          component: './500',
        },
      ],
    },
  ],
  disableRedirectHoist: true,

  /**
   * webpack 相关配置
   */
  define: {
    APP_TYPE: process.env.APP_TYPE || '',
  },
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
  theme: {
    'primary-color': primaryColor,
  },
  externals: {
    '@antv/data-set': 'DataSet',
  },
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
  proxy: {
    "/api/user": {
      "target": "http://localhost:8080/",
      "changeOrigin": true,
      "pathRewrite": { "^/api": "" }
    },
    "/api/competition": {
      "target": "http://localhost:8080/",
      "changeOrigin": true,
      "pathRewrite": { "^/api": "" }
    },
  }
};
